package com.digital.herbarium.task;

import com.digital.herbarium.service.BaseLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class InitBaseLibrary {

    @Autowired
    BaseLibraryService baseLibraryService;

    public static List<Map<String,Object>> treeList = new ArrayList<Map<String,Object>>();


    @Scheduled(cron ="0 0 1 * * ?")
    public void initDataByScheduled(){
//        if(treeList == null || treeList.size() ==0 ){
//           // System.out.println("开启定时任务");
//            init();
//        }
        treeList = null;
        init();

    }

    @Scheduled(cron ="0 0 1 * * ?")
    public void batchAddWater(){

    }

    // @PostConstruct
    public void init(){
        treeList = baseLibraryService.getBaseLibraryTree1();

    }
}
